<template>
	<view class="wrap">
		<u-form :model="model" :rules="rules" ref="uForm">
			<u-form-item label-width="350"
				:label-position="labelPosition" label="油补距(m)" prop="youBuJu">
				<u-input :border="border" placeholder="请输入油补距" v-model="model.youBuJu" type="digit"></u-input>
			</u-form-item>
			<u-form-item label-width="350"
				:label-position="labelPosition" label="油管挂及短节长度(m)" prop="youGuanGua">
				<u-input :border="border" placeholder="请输入油管挂及短节长度" v-model="model.youGuanGua" type="digit"></u-input>
			</u-form-item>
			<u-form-item label-width="350"
				:label-position="labelPosition" label="封隔器以上油管及附件总长(m)" prop="fengGaiQiShang">
				<u-input :border="border" placeholder="请输入封隔器以上油管及附件总长" v-model="model.fengGaiQiShang" type="digit"></u-input>
			</u-form-item>
			<u-form-item label-width="350"
				:label-position="labelPosition" label="封隔器接头上平面至胶筒中部以上长度(m)" prop="fengGaiQiJieTou">
				<u-input :border="border" placeholder="请输入封隔器接头上平面至胶筒中部以上长度" v-model="model.fengGaiQiJieTou" type="digit"></u-input>
			</u-form-item>
		</u-form>

		<u-button type="primary" @click="submit">计算</u-button>

		<view class="u-config-wrap">
			<view class="u-config-item">
				<view class="u-item-title">计算结果</view>
				<u-form-item style="font-size: 22px;" :leftIconStyle="{color: '#888', fontSize: '32rpx'}" label-width="300"
					:label-position="labelPosition" label="封隔器深度" prop="fengGaiQiShenDu">
					<span v-if="model.fengGaiQiShenDu"> {{model.fengGaiQiShenDu}} m </span>
				</u-form-item>
			</view>
			<view class="u-config-item">
				<view class="u-item-title">计算公式</view>
				<view class="u-item-desc">封隔器深度 = 油补距 + 油管挂及短节长度 + 封隔器以上油管及附件总长 + 封隔器接头上平面至胶筒中部以上长度</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				model: {
					youBuJu: '',
					youGuanGua: '',
					fengGaiQiShang: '',
					fengGaiQiJieTou: '',
					fengGaiQiShenDu: ''
				},
				rules: {
					youBuJu: [{
						required: true,
						message: '请输入油补距',
						trigger: 'blur'
					}],
					youGuanGua: [{
						required: true,
						message: '请输入油管挂及短节长度',
						trigger: 'blur'
					}],
					fengGaiQiShang: [{
						required: true,
						message: '请输入封隔器以上油管及附件总长',
						trigger: 'blur'
					}],
					fengGaiQiJieTou: [{
						required: true,
						message: '请输入封隔器接头上平面至胶筒中部以上长度',
						trigger: 'blur'
					}]
				},
				labelPosition: 'left',
				border: true,
				
			};
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		},
		methods: {
			submit() {
				this.$refs.uForm.validate(valid => {
					if (valid) {
						this.model.fengGaiQiShenDu = (
							parseFloat(this.model.youBuJu) + 
							parseFloat(this.model.youGuanGua) + 
							parseFloat(this.model.fengGaiQiShang) + 
							parseFloat(this.model.fengGaiQiJieTou)
						).toFixed(2);
					}
				});
			}
		}
	};
</script>

<style scoped lang="scss">
	.wrap {
		padding: 30rpx;
	}

	.u-config-wrap {
		margin-top: 30rpx;
	}

	.u-config-title {
		padding: 20rpx;
		font-size: 32rpx;
		font-weight: bold;
	}

	.u-config-item {
		padding: 20rpx;
	}

	.u-item-title {
		font-size: 28rpx;
		font-weight: bold;
		margin-bottom: 10rpx;
	}

	.u-item-desc {
		font-size: 24rpx;
		color: #666;
	}
</style>